package com.woniu.supermarket.web;


import com.woniu.supermarket.result.ResultResponse;
import com.woniu.supermarket.util.CodeCreateUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("code")
@Api(value = "生成编码的操作")
public class CreateCodeController {

    @GetMapping("/getPurchaseNumber")
    @ApiOperation(value = "生成采购订单编码")
    public ResultResponse<String> getPurchaseNumber(){
        ResultResponse<String> result = null;
        try {
            String purchaseCode = CodeCreateUtil.createPurchaseCode();
            result = new ResultResponse<>(200,"生成采购订单编码成功!",purchaseCode);
        }catch (RuntimeException e){
            e.printStackTrace();
            result = new ResultResponse<>(201,"系统错误!");
        }
        return result ;

    }

    @GetMapping("/getPromotionNumber")
    @ApiOperation(value = "生成促销编码")
    public ResultResponse<String> getPromotionNumber(){
        ResultResponse<String> result = null;
        try {
            String promotionCode = CodeCreateUtil.createPromotionCode();
            result = new ResultResponse<>(200,"生成编码成功!",promotionCode);
        }catch (RuntimeException e){
            e.printStackTrace();
            result = new ResultResponse<>(201,"系统错误!");
        }
        return result ;

    }


}
